<template>
	<view class="rent">
		<view class="searchBox marginTop10" >
			<image src="../../../static/img/each.png" mode=""></image>
			<input type="text" value="" placeholder="输入关键词搜索标准件" @tap="getnav(router(`searchRent`))"/>
		</view>
		<view class="type disFlex">
			
			<view :class="-1==activeIndex?'active':''" @tap="chenge(-1,'')">全部</view>
			
			<view  v-for="(val,index) in typeList" :key = "index" @tap="chenge(index,val.id)">
				<view :class="index == activeIndex?'active':''" >{{val.name}}</view>
			</view>
			<image @tap="getnav(router(`rentClass`))" src="../../../static/img/class.png" mode=""></image>
		</view>
		
		<view class="list" v-if="info.length>0">
			<view class="activeList"  v-for="(val,i) in info" @tap="torentdetall(val.id)" :key='i'>
				<view v-if="v.types!=null" class="iconstxt">{{v.types.name}}</view>
				<image :src="val.cover" mode=""></image>
				<view class="line2 describe">{{val.title}}</view>
				<view class="priceBox disFlex">
					<view>
						<text class="price">{{val.price}}</text>
						<text class="numbers">/件/天</text>
						<text class="word" style="color: #ccc;">非会员价</text>
					</view>
					<text class="word">{{val.min}}件起租</text>
				</view>
					<view  class="priceBox" style="margin-top: -5rpx;">
						<text class="price">{{val.member_price==null?val.price:val.member_price}}</text>
						<text class="numbers" style="color: #FE7203;font-size: 20rpx;">/件/天</text>
						<text class="word" style="color: red;">会员价</text>
					</view>
			</view>
		</view>
		<view class="listnull" v-else>
			<image src="../../../static/img/fail.png" mode=""></image>
			<view class="text">
				搜索结果为空
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeIndex:-1,
				typeList:[],
				info:[],
				page:1,
			}
		},
		onLoad() {
		this.getclass()
		this.choose(-1,'')
		},
		methods: {
			getclass(){
				this.http('/api/category/index', 'post', {}, )
					.then((res) => {
						let cla = res.data
						cla.forEach((v)=>{
							this.typeList.push({id:v.id,name:v.name})
						})
					})
			},
			choose(index,id){
				
				this.http('/api/standard/index', 'post', {category:id||'',page:this.page}, )
					.then((res) => {
						if(this.page>1){
							if(res.data.data.length>0){
								res.data.data.map((v)=>{
									this.info.push( v)
								})
							}else{
								uni.showToast({ title: '已经没有数据了!', icon: 'none' })
							}
						}else{
							this.info=res.data.data
						}
							console.log(this.info)
					})
			},
			torentdetall(v){
				uni.navigateTo({
					url: '/pages/index/rent/rentDetail?id=' + v
				});
			},
			chenge(index,id){
				this.activeIndex = index;
				this.page=1
				this.choose(index,id)
			}
		},
		onReachBottom(){
			uni.showLoading({
			    title: '加载中'
			});
			++this.page
			this.choose()
			setTimeout(function () {
			    uni.hideLoading();
			}, 1000);
		},
	}
</script>

<style lang="less">
	.listnull{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 100rpx;
		image{
			width: 100rpx;
			height: 100rpx;
			// margin: 0 auto;
		}
		.text{
			font-size: 30rpx;
			color: #ccc;
			
		}
	}
	.rent{
		padding: 0 40rpx;
		.searchBox{
			height:80rpx;
			background:rgba(245,245,249,1);
			border-radius:40rpx;
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			image{
				width: 34rpx;
				height: 34rpx;
			}
			input{
				padding-left: 8rpx;
				width: 100%;
			}
		}
		.type{
			margin-top: 50rpx;
			>view{
				display: flex;
				align-items: center;
				color: #262626;
			}
			image{
				width: 32rpx;
				height: 32rpx;
			}
			.active{
				color: #2291FF!important;
			}
		}
		
		.list{
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;
			margin-top: 22rpx;
			.activeList{
				width: 325rpx;
				margin-top: 32rpx;
				position: relative;
				.iconstxt {
					height: 36rpx !important;
					background-color: #FFCF59;
					border-radius: 16px 0px 16px 0pX;
					padding: 0 23rpx;
					position: absolute;
					top: -8rpx;
					left: -8rpx;
					color: #fff;
					font-size: 24rpx;
					z-index: 888;
				}
				image{
					width: 100%;
					height: 188rpx;
					border-radius: 20rpx;
				}
				.describe{
					font-size: 24rpx;
					padding-top: 10rpx;
				}
				.priceBox{
					margin-top: 25rpx;
					.price{
						color: #FE7203;
						&::before{
							// padding-right: 5rpx;
							font-size: 20rpx;
						}
					}
					.numbers{
						color: #FE7203;
						font-size: 20rpx;
					}
					.word{
						font-size: 20rpx;
						color: #BEC9D7;
						padding-left: 10rpx;
					}
				}
			}
		}
	}
</style>
